package com.cooper.service.admin;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cooper.resource.IResourceManager;

/**
 * 提供暂存服务, 如商品编辑页面中的描述信息暂存
* @Description: 
* @version: v1.0.0
* @author: coral coraldane@163.com
* @date: Feb 15, 2015 1:22:48 PM
*
* Modification History:
*  Date              Author          Version            Description
*-------------------------------------------------------------------*
* Feb 15, 2015      coraldane        v1.0.0
 */
@Service
public class SavedService {
	
	protected Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private IResourceManager resourceManager;
	
	public static final String SAVED_KEY_PREFIX = "SAVED_";
	
	/**
	 * 保存暂存信息
	 * 如商品描述信息暂存
	 * type1: resName - PRODUCT_DESC, key - ITEM_12, value - 详细描述HTML
	 * type2: resName - PRODUCT_DESC, key - USER_1, value - 详细描述HTML
	 * @param resName
	 * @param key
	 * @param value
	 */
	public void doSave(String resName, String key, String value){
		this.resourceManager.writeResItem(SAVED_KEY_PREFIX + resName, key, value);
	}
	
	/**
	 * 获取暂存信息
	 * @param resName
	 * @param key
	 * @return
	 */
	public String doGet(String resName, String key){
		Object obj = this.resourceManager.getResItem(SAVED_KEY_PREFIX + resName, key);
		return null == obj?"":String.valueOf(obj);
	}

}
